package cn.hairui.blog.dao;

import cn.hairui.blog.entity.Message;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 留言表 Mapper 接口
 * </p>
 *
 * @author laoganbu
 * @since 2020-04-20
 */
@Mapper
public interface MessageMapper extends BaseMapper<Message> {

    @Select("SELECT\n" +
            "    t1.id,\n" +
            "    t1.artical_id AS articalId,\n" +
            "    t1.account,\n" +
            "    t1.content,\n" +
            "    t1.message_time AS messageTime,\n" +
            "    t2.nickname,\n" +
            "    t2.prophoto\n" +
            "FROM\n" +
            "    MESSAGE t1\n" +
            "LEFT JOIN\n" +
            "    USER t2\n" +
            "ON\n" +
            "    t1.account=t2.account\n" +
            "WHERE\n" +
            "    t1.artical_id=#{articalId} order by t1.id desc")
    List<Map> selectByArticalId(int articalId);

    @Select("select count(1) from message")
    int count();
}
